<template>
    <div class="addPermissionList">
         <el-dialog
             center
            :before-close="handClose"
            width="30%"
            title="用户信息管理"
            :visible.sync="off"
            append-to-body>
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" size="mini" class="demo-ruleForm">
                <el-form-item label="账号" prop="account">
                    <el-input v-model.trim="ruleForm.account"></el-input>
                </el-form-item>
                <el-form-item label="年龄" prop="age">
                    <el-input v-model.trim="ruleForm.age"></el-input>
                </el-form-item>
                <el-form-item label="头像" prop="avatar">
                    <el-input v-model.trim="ruleForm.avatar"></el-input>
                </el-form-item>
                <el-form-item label="生日" prop="birthday">
                    <el-input v-model.trim="ruleForm.birthday"></el-input>
                </el-form-item>
                <el-form-item label="手机号" prop="mobile">
                    <el-input v-model.trim="ruleForm.mobile"></el-input>
                </el-form-item>
                <el-form-item label="身份证号" prop="idCard">
                    <el-input v-model.trim="ruleForm.idCard"></el-input>
                </el-form-item>
                <el-form-item label="性别" prop="sex">
                    <el-radio-group v-model="ruleForm.sex">
                        <el-radio label="男">男</el-radio>
                        <el-radio label="女">女</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="create">立即创建</el-button>
            </div>
        </el-dialog>
    </div> 
</template>

<script>
    import { addPerssion } from "@/api/jurisdiction.js"
    export default {
        name: "add",
        props: {
            off: {
                type: Boolean
            },
            rowData: {
                type: Object
            },
        },
        watch: {
            off(val){
                if(val){
                    this.ruleForm = this.rowData;
                }
            }
        },
        data(){
            return {
               rules: {
                     account: [{required: true,message: "账户不能为空",trigger: "blur"}],
                     mobile: [{required: true,message: "手机号不能为空",trigger: "blur"}],
                     age: [{required: true,message: "年龄不能为空",trigger: "blur"}],
                },
                ruleForm: {
                    permissionName: "",
                    url:""
                }
            }
        },
        methods: {
            handClose(){
                this.$emit("update:off", false);
            },
            create(){
                this.$refs.ruleForm.validate((valid) => {
                    if(!valid){
                        return;
                    }else{
                        // var obj = {
                        //     permissionName: this.ruleForm.permissionName,
                        //     url: this.ruleForm.url
                        // }
                        addPerssion({
                            permissionName: this.ruleForm.permissionName,
                            url: this.ruleForm.url
                        }).then(
                            res => {
                                console.log("res新增权限", res);
                                this.$message({
                                    type: "success",
                                    message: "新增权限成功"
                                });
                                this.$emit("update:off", false);
                                this.$parent.getList();
                                this.ruleForm.resetFields();
                            },
                            err => {}
                        );
                    }
                });
            }
        }
    }
</script>

<style scoped lang="less">

</style>